/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* LogUtil.java
*
* Created on November 21, 2007, 9:19 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
 */
package javautil.io;

import javautil.collections.ArrayUtil;
import javautil.lang.StringUtil;

import java.text.DecimalFormat;
import java.text.Format;

/**
 *
 * @author stewari1
 */
public class LogUtil {

    /** Creates a new instance of LogUtil */
    public LogUtil() {}

    public static void print(Object[] objs) {

        for (int index = 0; index < objs.length - 1; index++) {

            System.out.print(objs[index] + " ");
        }

        System.out.println(objs[objs.length - 1]);
    }

    /**
     * Method description
     *
     * @param objs description
     * @param format description
     */
    private static void print(Object[] objs, Format format) {

        for (int index = 0; index < objs.length - 1; index++) {

            System.out.print(format.format(objs[index]) + " ");
        }

        System.out.println(format.format(objs[objs.length - 1]));
    }

    /**
     * Method description
     *
     * @param objs2D description
     */
    private static void print(Object[][] objs2D) {

        for (Object[] obj1D : objs2D) {

            print(obj1D);
        }
    }

    /**
     *
     * @param objs2D any 2dim array objects. <code>toString()</code> will be used for printing the cell.
     * @param horiCellPadding # of <code>char</code>s to use
     * @param vertCellPadding # of lines
     */
    public static void print(Object[][] objs2D, int horiCellPadding, int vertCellPadding,
                             Format format) {
        System.out.println(IOUtil.toString(objs2D, horiCellPadding, vertCellPadding, format));
    }

    public static void print(int[][] a) {
        print(ArrayUtil.getIntegerArray(a));
    }

    public static void print(int[] a) {
        print(ArrayUtil.getIntegerArray(a));
    }

    public static void print(double[] a) {
        print(ArrayUtil.getDoubleArray(a));
    }

    public static void print(double[] a, DecimalFormat decimalFormat) {
        print(ArrayUtil.getDoubleArray(a), decimalFormat);
    }

    public static void print(double[][] a) {
        print(ArrayUtil.getDoubleArray(a), 2, 1, null);
    }

    public static void print(double[][] a, int horiCellPadding, int vertCellPadding,
                             Format format) {
        print(ArrayUtil.getDoubleArray(a), horiCellPadding, vertCellPadding, format);
    }

    public static void main(String[] args) {

        String[][] str2DArray = new String[4][4];

        StringUtil.setWithEmptyStr(str2DArray, "Tanusree");

        str2DArray[2][3] = "";
        str2DArray[3][2] = "Susanta";

        double[][] doubleArray = {

            { 0.9518652226233454, 0.000001, 0.000001 }, { 0.000001, 0.000001, 0.000001 },
            { 0.000001, 0.000001, 0.000001 }
        };


        // print(str2DArray, 1, 1,null);
        print(doubleArray, 2, 1, new DecimalFormat("0.####"));
        print(doubleArray);
    }
}
